package com.xzgj.fmmall.controller;

import com.xzgj.fmmall.entity.User;
import com.xzgj.fmmall.service.UserService;
import com.xzgj.fmmall.vo.ResStatus;
import com.xzgj.fmmall.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
@Api(value = "提供用户的登录和注册接口",tags = "用户管理")
public class UserController {

    @Resource
    private UserService userService;

    //只有一个参数时，默认为get
    @ApiOperation("用户登录接口")
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public ResultVO login(@RequestBody User user){
        return userService.checkLogin(user.getUserName(),user.getPassword());
    }

    @ApiOperation("用户注册接口")
    /**
     *如果传参是对象，就不需要在方法里面加参数说明注解
     */
    @RequestMapping(value = "/register",method = RequestMethod.POST)
    public ResultVO register(@RequestBody User user){

        return userService.userRegister(user.getUserName(),user.getPassword());
    }

    @ApiOperation("查询用户信息接口")
    @RequestMapping(value = "/info/{userId}",method = RequestMethod.GET)
    public ResultVO getUserInfo(@PathVariable("userId") String userId){

        return userService.getUserInfoByUserId(userId);
    }

    @ApiOperation("查询用户列表接口")
    @RequestMapping(value = "/selectUsers",method = RequestMethod.GET)
    public ResultVO selectUsers(){
        return userService.queryUsers();
    }

    @ApiOperation("更新用户基本信息接口")
    @PutMapping(value = "/info")
    public ResultVO updateUserInfo(@RequestBody User user){

        return userService.updateUserInfoByUserId(user);
    }

    /**
     *如果传参是对象，就不需要在方法里面加参数说明注解
     */
    @ApiOperation("校验token是否过期接口")
    @PostMapping(value = "/check")
    public ResultVO userTokenCheck(@RequestHeader("token") String token){
        return userService.checkTokenIsValid(token);
    }
}
